package com.xy.servicemanage.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.servicemanage.CouponTemplate;
import com.xy.servicemanage.service.ICouponTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 优惠券模板Controller
 *
 * @author ruoyi
 * @date 2025-06-23
 */
@RestController
@RequestMapping("/template")
public class CouponTemplateController extends BaseController
{
    @Autowired
    private ICouponTemplateService couponTemplateService;

    /**
     * 查询优惠券模板列表
     */
    @RequiresPermissions("servicemanage:template:list")
    @GetMapping("/list")
    public TableDataInfo list(CouponTemplate couponTemplate)
    {
        startPage();
        List<CouponTemplate> list = couponTemplateService.selectCouponTemplateList(couponTemplate);
        return getDataTable(list);
    }

    /**
     * 导出优惠券模板列表
     */
    @RequiresPermissions("servicemanage:template:export")
    @Log(title = "优惠券模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CouponTemplate couponTemplate)
    {
        List<CouponTemplate> list = couponTemplateService.selectCouponTemplateList(couponTemplate);
        ExcelUtil<CouponTemplate> util = new ExcelUtil<CouponTemplate>(CouponTemplate.class);
        util.exportExcel(response, list, "优惠券模板数据");
    }

    /**
     * 获取优惠券模板详细信息
     */
    @RequiresPermissions("servicemanage:template:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(couponTemplateService.selectCouponTemplateById(id));
    }

    /**
     * 新增优惠券模板
     */
    @RequiresPermissions("servicemanage:template:add")
    @Log(title = "优惠券模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CouponTemplate couponTemplate)
    {
        return toAjax(couponTemplateService.insertCouponTemplate(couponTemplate));
    }

    /**
     * 修改优惠券模板
     */
    @RequiresPermissions("servicemanage:template:edit")
    @Log(title = "优惠券模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CouponTemplate couponTemplate)
    {
        return toAjax(couponTemplateService.updateCouponTemplate(couponTemplate));
    }

    /**
     * 删除优惠券模板
     */
    @RequiresPermissions("servicemanage:template:remove")
    @Log(title = "优惠券模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(couponTemplateService.deleteCouponTemplateByIds(ids));
    }
}

